package cool.mtc.base.plugin.generator.code.model.template.bg;

import cool.mtc.base.plugin.generator.code.model.template.BaseTemplateParam;
import cool.mtc.core.util.StringUtil;
import lombok.Data;
import lombok.EqualsAndHashCode;

/**
 * @author 明河
 */
@Data
@EqualsAndHashCode(callSuper = true)
public abstract class BaseBgTemplateParam extends BaseTemplateParam {

    /**
     * 作者
     */
    private String author = "yz";

    /**
     * Entity层基础包路径
     */
    private String entityBasePackage;

    /**
     * Controller层基础包路径
     */
    private String controllerBasePackage;

    /**
     * Service层基础包路径
     */
    private String serviceBasePackage;

    /**
     * Manager层基础包路径
     */
    private String managerBasePackage;

    /**
     * Dao层基础包路径
     */
    private String daoBasePackage;

    /**
     * Model层基础包路径
     */
    private String modelBasePackage;

    /**
     * 生成类相对于基础包的相对包路径
     */
    private String relativePackage;

    @Override
    public String getTargetFilePath() {
        return this.fixPath(this.getProjectPath()) +
                "src/main/java/" +
                this.fixPath(this.getPackage().replace(StringUtil.POINT, StringUtil.SLASH)) +
                this.getClassName() +
                this.getExtensionName();
    }

    public String getPackage() {
        if (StringUtil.isEmpty(this.getRelativePackage())) {
            return this.getBasePackage();
        }
        return this.getBasePackage() + StringUtil.POINT + this.getRelativePackage();
    }

    public abstract String getBasePackage();

    public abstract String getClassName();

    public void handleCheckParamsCorrect() {
        super.handleCheckParamsCorrect();
        if (StringUtil.isEmpty(this.getPackage())) {
            throw new RuntimeException(this.handleMessage("未设置[getPackage()]"));
        }
        if (StringUtil.isEmpty(this.getClassPrefix())) {
            throw new RuntimeException(this.handleMessage("未设置[classPrefix]"));
        }
    }
}
